package com.woniu.liuzhougov.itemQueryAndNotice.mapper;

import com.woniu.liuzhougov.authorityControl.pojo.User;
import com.woniu.liuzhougov.itemAndTask.pojo.*;
import com.woniu.liuzhougov.itemQueryAndNotice.dynamicprovider.QuerySx;
import com.woniu.liuzhougov.itemQueryAndNotice.vo.AreaStatistic;
import com.woniu.liuzhougov.itemQueryAndNotice.vo.DepartmentStatistic;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface SxMapper {
    @Results({
      @Result(id =true,column = "item_id",property = "itemId"),
      @Result(column ="item_type_id",property = "itemType",one=@One(
              select = "findTypeById"
      )),
      @Result(column = "item_urgency_id",property = "itemUrgency",one = @One(
              select = "findUrgencyById"
      )),
      @Result(column = "check_status_id",property = "itemStatus",one = @One(
              select = "findCheckStatusById"
      )),
      @Result(column = "area_id",property = "area",one = @One(
              select = "findAreaById"
      )),
      @Result(column = "item_name",property = "itemName"),
      @Result(column = "item_time",property = "itemTime"),
      @Result(column = "item_content",property = "itemContent"),
      @Result(column = "item_remark",property = "itemRemark"),
      @Result(column = "item_founder_id",property = "itemFounder", one= @One(
              select = "findUserById"
      ))
    })
    @Select("select * from tb_user")
    public List<User> findFounder();


    @Select("select * from tb_user where user_id = #{item_founder_id}")
    public User findUserById(Integer item_founder_id);

    @Select("select * from tb_item_type where item_type_id = #{item_type_id}")
    public ItemType findTypeById(Integer item_type_id);

    @Select("select * from tb_urgenry where urgenry_id = #{item_urgency_id}")
    public Urgenry findUrgencyById(Integer item_urgency_id);

    @Select("select * from tb_check_status where check_status_id = #{check_status_id}")
    public CheckStatus findCheckStatusById(Integer check_status_id);

    @Select("select * from tb_area where area_id = #{area_id}")
    public Area findAreaById(Integer area_id);

    @Select("select * from tb_urgenry")
    public List<Urgenry> findUrgenry();

    @Select("select * from tb_check_status")
    public List<CheckStatus> findStatue();


    @Results({
            @Result(id =true,column = "item_id",property = "itemId"),
            @Result(column ="item_type_id",property = "itemType",one= @One(
                    select = "findTypeById"
            )),
            @Result(column = "item_urgency_id",property = "itemUrgency",one = @One(
                    select = "findUrgencyById"
            )),
            @Result(column = "check_status_id",property = "itemStatus",one = @One(
                    select = "findCheckStatusById"
            )),
            @Result(column = "area_id",property = "area",one = @One(
                    select = "findAreaById"
            )),
            @Result(column = "item_name",property = "itemName"),
            @Result(column = "item_time",property = "itemTime"),
            @Result(column = "item_content",property = "itemContent"),
            @Result(column = "item_remark",property = "itemRemark"),
            @Result(column = "item_founder_id",property = "itemFounder", one= @One(
                    select = "findUserById"
            ))
    })
    @SelectProvider(type = QuerySx.class,method = "findItems")
    public  List<Item> queryItems(@Param("checkStatus")CheckStatus checkStatus, @Param("user")User user, @Param("urgency") Urgenry urgency, @Param("item")Item item);
    @Results({
            @Result(id =true,column = "item_id",property = "itemId"),
            @Result(column ="item_type_id",property = "itemType",one= @One(
                    select = "findTypeById"
            )),
            @Result(column = "item_urgency_id",property = "itemUrgency",one = @One(
                    select = "findUrgencyById"
            )),
            @Result(column = "check_status_id",property = "itemStatus",one = @One(
                    select = "findCheckStatusById"
            )),
            @Result(column = "area_id",property = "area",one = @One(
                    select = "findAreaById"
            )),
            @Result(column = "item_name",property = "itemName"),
            @Result(column = "item_time",property = "itemTime"),
            @Result(column = "item_content",property = "itemContent"),
            @Result(column = "item_remark",property = "itemRemark"),
            @Result(column = "item_founder_id",property = "itemFounder", one= @One(
                    select = "findUserById"
            ))
    })
    @SelectProvider(type = QuerySx.class,method = "findCityItems")
    public List<Item> cityQueryItems(@Param("checkStatus")CheckStatus checkStatus, @Param("user")User user, @Param("urgency") Urgenry urgency, @Param("item")Item item);

    @Results({
            @Result(column = "area_name",property = "areaName"),
            @Result(column = "count(*)",property = "count")
    })
    @Select("select count(*) ,area_name from tb_item,tb_area  where tb_item.area_id=tb_area.area_id and flag = 0 group by tb_item.area_id")
    public  List<AreaStatistic> queryCountByArea();



    @Results({
            @Result(column = "department_name",property = "departmentName"),
            @Result(column = "count(*)",property = "count")
           }
    )
    @Select("select count(*),department_name FROM tb_item,tb_department WHERE tb_item.department_id=tb_department.department_id AND flag = 0 GROUP BY tb_item.department_id;")
    public List<DepartmentStatistic> queryCountByDepartment();



}

